package com.njupt.sellsec.service.Impl;

import com.njupt.sellsec.dao.GoodsDao;
import com.njupt.sellsec.domain.SecGoods;
import com.njupt.sellsec.service.GoodsService;
import com.njupt.sellsec.vo.GoodsFormVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: XJL
 * @Description:
 * @Date: Create in 11:02 2018/7/29
 * @Modified By:
 **/
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsDao goodsDao;

    @Override
    public List<GoodsFormVO> getGoodsVOListById() {

        List<GoodsFormVO> goodsFormVOList = goodsDao.getGoodsVOListById();
        return goodsFormVOList;
    }

    @Override
    public GoodsFormVO getGoodInfoById(long goodsId) {
        GoodsFormVO goodsFormVO = goodsDao.getGoodInfoById(goodsId);
        return goodsFormVO;
    }

    @Override
    public boolean decreaseStock(Long id) {
        int result = goodsDao.decreaseStock(id);
        return result>0;
    }

    @Override
    public void resetStock(List<GoodsFormVO> goodsFormVOList) {
        for(GoodsFormVO goods : goodsFormVOList ) {
            SecGoods g = new SecGoods();
            g.setGoodsId(goods.getId());
            g.setStockCount(goods.getStockCount());
            goodsDao.resetStock(g);
        }
    }
}
